package com.dyz.leetcode._12_linkedList;

import com.dyz.leetcode.ListNode;

public class _82_deleteDuplicates {
    public ListNode deleteDuplicates(ListNode head) {
        if(head==null||head.next==null){return head;}
        ListNode dummy = new ListNode(-1);
        dummy.next = head;
        ListNode pre = dummy;
        ListNode curr = dummy.next;

        while (curr!=null){
            if(curr.next!=null && curr.next.val==curr.val){
                do{
                    curr = curr.next;
                }while (curr.next!=null && curr.next.val==curr.val );
                pre.next = curr.next;
                curr.next=null;

            }else {
                pre = curr;
            }
            curr = pre.next;
        }
        return dummy.next;
    }
}
